//
//  ChainNetStatus.m
//  Chain
//
//  Created by zhaosh on 2018/3/30.
//  Copyright © 2018年 zhaosh. All rights reserved.
//

#import "ChainNetStatus.h"

@implementation ChainNetStatus

static ChainNetStatus *g_instance = nil;

/**
 *@brief           get the signalton engine object
 *@return          the engine object
 */
+ (ChainNetStatus *)sharedInstance
{
    static ChainNetStatus *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[ChainNetStatus alloc]init];
    });
    return _sharedClient;
}

-(instancetype)init{
    if(self = [super init]){
        
    }
    return self;
}


/**
 *@brief           get the network statue
 */
- (BOOL)isNetworkReachable
{
    BOOL isReachable = NO;
    Reachability *reachability = [Reachability reachabilityWithHostname:@"www.baidu.com"];
    switch ([reachability currentReachabilityStatus]) {
        case NotReachable:{
            isReachable = NO;
        }
            break;
        case ReachableViaWWAN:{
            isReachable = YES;
        }
            break;
        case ReachableViaWiFi:{
            isReachable = YES;
        }
            break;
        default:
            isReachable = NO;
            break;
    }
    return isReachable;
}

/**
 *@brief           Judgment wifi is connected
 */
- (BOOL)isEnableWIFI
{
    
    BOOL isExistenceNetwork = YES;
    Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
    switch ([reach currentReachabilityStatus]) {
        case NotReachable:
            isExistenceNetwork = NO;
            //DebugLog(@"notReachable");
            break;
        case ReachableViaWiFi:
            isExistenceNetwork = YES;
            //DebugLog(@"WIFI");
            break;
        case ReachableViaWWAN:
            isExistenceNetwork = NO;
            //DebugLog(@"3G");
            break;
    }
    
    return isExistenceNetwork;
    
    //    return ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != NotReachable);
}

/**
 *@brief           To judge whether the 3G connection
 */
- (BOOL)isEnable3G
{
    BOOL isExistenceNetwork = YES;
    Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
    switch ([reach currentReachabilityStatus]) {
        case NotReachable:
            isExistenceNetwork = NO;
            //DebugLog(@"notReachable");
            break;
        case ReachableViaWiFi:
            isExistenceNetwork = NO;
            //DebugLog(@"WIFI");
            break;
        case ReachableViaWWAN:
            isExistenceNetwork = YES;
            //DebugLog(@"3G");
            break;
    }
    
    return isExistenceNetwork;
    
    //    return ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] != NotReachable);
}


@end
